package logic

import (
	"context"
	"pet/models"

	"pet/petrpc/internal/svc"
	"pet/petrpc/petrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type PetShowLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewPetShowLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PetShowLogic {
	return &PetShowLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *PetShowLogic) PetShow(in *petrpc.PetShowRequest) (*petrpc.PetShowResponse, error) {
	// todo: add your logic here and delete this line

	var pet models.Pet

	models.DB.Debug().Model(&models.Pet{}).
		Select("pets.*,classes.`name` AS class_name").
		Where("pets.id = ?", in.PetId).
		Joins("LEFT JOIN classes ON pets.class_id = classes.id").
		Find(&pet)

	return &petrpc.PetShowResponse{
		Name:    pet.Name,
		Sex:     pet.Sex,
		Info:    pet.Info,
		Image:   pet.Image,
		ClassId: pet.ClassId,
	}, nil
}
